package sample;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import service.Jedis;

@Controller
@RequestMapping(value="/safe")
public class safeSample {
	@Resource(name="jedis-client")
	Jedis jedis;
	@RequestMapping(value="/add",method =RequestMethod.POST)
	public String addAndGet(Model model){
		model.addAttribute("result",jedis.incr("num"));
		System.out.println("add!");
		return "add";
	}
	@RequestMapping(value="/add",method=RequestMethod.GET)
	public String get(Model model){
		model.addAttribute("result",jedis.incrBy("num", 0));
		System.out.println("get!");
		return "add";
	}
	@RequestMapping(value="/clear",method=RequestMethod.GET)
	public String clear(Model model){
		model.addAttribute("result",jedis.del("num"));
		System.out.println("clear success");
		return "add";
	}
	
}
